import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;

public class UnitTest {

	private PokerGame game;
	private Deck deck;
	private ArrayList<Card> pairHand = new ArrayList<Card>();
	private ArrayList<Card> twoPairHand = new ArrayList<Card>();
	private ArrayList<Card> threeHand = new ArrayList<Card>();
	private ArrayList<Card> fourHand = new ArrayList<Card>();
	private ArrayList<Card> flushHand = new ArrayList<Card>();
	private ArrayList<Card> fullHouseHand = new ArrayList<Card>();
	private ArrayList<Card> sortHand = new ArrayList<Card>();
	private ArrayList<Card>	suitCountHand = new ArrayList<Card>();
	private ArrayList<Card> royalStraightFlushHand = new ArrayList<Card>();
	private Card cAce;
	private Card cSix;
	
	@Before
	public void setup() {
		
		game = new PokerGame();
		deck = new Deck();
		
		cSix = new Card(Face.SIX, Suit.CLUBS);
		Card cTwo = new Card(Face.TWO, Suit.CLUBS);
		Card cThree = new Card(Face.THREE, Suit.CLUBS);
		Card cFour = new Card(Face.FOUR, Suit.CLUBS);
		Card cFive = new Card(Face.FIVE,Suit.CLUBS);
		
		cAce = new Card(Face.ACE, Suit.CLUBS);
		Card cKing = new Card(Face.KING, Suit.CLUBS);
		Card cQueen = new Card(Face.QUEEN, Suit.CLUBS);
		Card cJack = new Card(Face.JACK, Suit.CLUBS);
		Card cTen = new Card(Face.TEN, Suit.CLUBS);
		
		sortHand.add(cFive);
		sortHand.add(cFour);
		sortHand.add(cThree);
		sortHand.add(cTwo);
		sortHand.add(cSix);
		
		suitCountHand.add(new Card(Face.ACE, Suit.CLUBS));
		suitCountHand.add(new Card(Face.EIGHT, Suit.SPADES));
		suitCountHand.add(new Card(Face.TWO, Suit.CLUBS));
		suitCountHand.add(new Card(Face.THREE, Suit.CLUBS));
		suitCountHand.add(new Card(Face.FIVE, Suit.DIAMONDS));
		
		pairHand.add(new Card(Face.TEN, Suit.HEARTS));
		pairHand.add(new Card(Face.TEN, Suit.CLUBS));
		pairHand.add(new Card(Face.THREE, Suit.CLUBS));
		pairHand.add(new Card(Face.EIGHT, Suit.DIAMONDS));
		pairHand.add(new Card(Face.SEVEN, Suit.SPADES));
		
		twoPairHand.add(new Card(Face.TEN, Suit.HEARTS));
		twoPairHand.add(new Card(Face.TEN, Suit.CLUBS));
		twoPairHand.add(new Card(Face.EIGHT, Suit.CLUBS));
		twoPairHand.add(new Card(Face.SEVEN, Suit.DIAMONDS));
		twoPairHand.add(new Card(Face.EIGHT, Suit.SPADES));
		
		threeHand.add(new Card(Face.TEN, Suit.HEARTS));
		threeHand.add(new Card(Face.TEN, Suit.CLUBS));
		threeHand.add(new Card(Face.THREE, Suit.CLUBS));
		threeHand.add(new Card(Face.TEN, Suit.DIAMONDS));
		threeHand.add(new Card(Face.SEVEN, Suit.SPADES));
		
		fourHand.add(new Card(Face.TEN, Suit.HEARTS));
		fourHand.add(new Card(Face.TEN, Suit.CLUBS));
		fourHand.add(new Card(Face.THREE, Suit.CLUBS));
		fourHand.add(new Card(Face.TEN, Suit.DIAMONDS));
		fourHand.add(new Card(Face.TEN, Suit.SPADES));
		
		flushHand.add(cSix);
		flushHand.add(cTwo);
		flushHand.add(cThree);
		flushHand.add(cFour);
		flushHand.add(cFive);
		
		fullHouseHand.add(new Card(Face.TEN, Suit.HEARTS));
		fullHouseHand.add(new Card(Face.TEN, Suit.CLUBS));
		fullHouseHand.add(new Card(Face.THREE, Suit.CLUBS));
		fullHouseHand.add(new Card(Face.TEN, Suit.DIAMONDS));
		fullHouseHand.add(new Card(Face.THREE, Suit.SPADES));
		
		royalStraightFlushHand.add(cTen);
		royalStraightFlushHand.add(cQueen);
		royalStraightFlushHand.add(cKing);
		royalStraightFlushHand.add(cAce);
		royalStraightFlushHand.add(cJack);
	}
	
	@Test
	public void testCardCompareTo() {
		assertEquals(0, new Card(Face.ACE, Suit.SPADES).compareTo(cAce));
		assertEquals(true, cSix.compareTo(cAce) < 0);
		assertEquals(true, cAce.compareTo(cSix) > 0);
		assertEquals(-8, cSix.compareTo(cAce));
		assertEquals(8, cAce.compareTo(cSix));
	}
	
	@Test
	public void testDeckSize() {
		assertEquals(52, deck.size());
	}
	
	@Test
	public void testShuffle() {
		
		int originalTopCardValue = deck.pop().value();
		deck.shuffle();
		int shuffledTopCardValue = deck.pop().value();
		
		assertEquals(false, originalTopCardValue == shuffledTopCardValue);
	}
	
	@Test
	public void testSort() {
		assertEquals(2, game.sortHandByValue(sortHand).get(0).value());
		assertEquals(3, game.sortHandByValue(sortHand).get(1).value());
		assertEquals(4, game.sortHandByValue(sortHand).get(2).value());
		assertEquals(5, game.sortHandByValue(sortHand).get(3).value());
		assertEquals(6, game.sortHandByValue(sortHand).get(4).value());
	}
	
	@Test
	public void testSuitCount() {
		assertEquals(3, game.getCountOfSameSuit(suitCountHand));
	}
	
	@Test
	public void testHigh() {
		assertEquals(cAce, game.getHighCard(royalStraightFlushHand));
		assertEquals(cSix, game.getHighCard(flushHand));
	}
	
	@Test
	public void testPair() {
		assertEquals(true, game.isPair(pairHand));
	}
	
	@Test
	public void testTwoPair() {
		assertEquals(true, game.isTwoPair(twoPairHand));
	}
	
	@Test
	public void testThree() {
		assertEquals(true, game.isThree(threeHand));
	}
	
	@Test
	public void testFour() {
		assertEquals(true, game.isFour(fourHand));
	}
	
	@Test
	public void testFlush() {
		assertEquals(true, game.isFlush(flushHand));
	}
	
	@Test
	public void testFullHouse() {
		assertEquals(true, game.isFullHouse(fullHouseHand));
	}
	
	@Test
	public void testStraight() {
		assertEquals(true, game.isStraight(sortHand));
	}
	
	@Test
	public void testAceHighStraight() {
		assertEquals(true, game.isStraight(royalStraightFlushHand));
	}
	
	//@Test
	//public void testRoyalFlush() {
		//assertEquals(TypeOfHand.ROYAL_FLUSH, game.evaluateHand(royalStraightFlushHand));
	//}

}
